#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<string.h>

size_t my_strlen(const char* str)
{
	assert(str);
	int count = 0;
	while (*str++!='\0')
	{
		count++;
	}
	return count;
}
int my_strlen2(const char* str)
{
	assert(str);

	if (*str == '\0')
	{
		return 0;
	}
	else
	{
		return 1 + my_strlen2(++str);
	}
}
int  my_strlen3(const char* str)
{
	assert(str);
	char* cur = str;
	while (*cur)
	{
		cur++;
	}
	return cur - str;
}
char* my_strcpy(char* dest, const char* sor)
{
	assert(dest&&sor);
	char* ret = dest;
	while (*ret++ = *sor++)
	{
		;
	}
	return dest;
}
char * my_strcat(char* dest,const char* sor)
{
	assert(dest&&sor);
	char* tmp = dest;
	while (*tmp++)
	{
		;
	}
	while (*tmp++ = *sor++)
	{
		;
	}
	return dest;
}
int my_strcmp(const char* str1,const char*str2)
{
	assert(str1&&str2);
	while(*str1 == *str2)
	{
		if (*str1 == '\0')
			return 0;
		str1++;
		str2++;
	}
	return *str1 - *str2;
}
//int main()
//{
//	char arr[20] = "axzzxxcc";
//	char arr2[] = "";
//	//int ret=my_strcmp(arr, arr2);
//	//printf("%d", ret);
//	int tmp=my_strlen2(arr);
//	//my_strcpy(arr, arr2);
//	//strcat(arr, "yes");
//	//my_strcat(arr, arr2);
//	printf("%d\n", tmp);	
//	//printf("%s\n", my_strcpy(arr, arr2));
//	//printf("%s\n", arr);	
//	//printf("%d\n", strcmp(arr, arr2));
//
//	return 0;
//}
//int main()
//{
//
//	char arr1[] = "abcdefgh";
//	char arr2[] = "xxx";
//	strcpy(arr1, arr2);
//	printf("%s\n", arr1);
//	
//
//	return 0;
//
//}
char* my_strncpy(char* dest,char* sor,int size)
{
	char* str = dest;
	assert(dest&&sor);
	while (size--)
	{
		if (*sor)
		{
			*str++ = *sor++;
		}
		
		else
		{
			*str++ = '\0';
		}

	}
	return dest;
}
//int main()
//{
//	char arr1[] = "abcdefgh";
//	char arr2[] = "xxx";
//	strncpy(arr1, arr2, 3);
//	printf("%s\n", arr1);
//	return 0;
//}
char * my_strncat(char* dest, char* sor, int size)
{
	int count = 0;
	char* str1 = dest;
	while (*str1)
	{
		str1++;

	}
	while (size--)
	{
		if (*sor)
		{
			*str1++ = *sor++;
		}

		else
		{
			*str1++ = '\0';
			return dest;
		}

	}
	*str1++ = '\0';
	return dest;

}
//int main()
//{
//	char arr1[20] = "abcdef\0XXXXXXX";
//	char arr2[] = "yes";
//	my_strncat(arr1, arr2, 1);
//	printf("%s\n", arr1);
//	return 0;
//}
int my_strncmp(char* str1, char* str2, int size)
{
	while (size--)
	{
		if(*str1 == *str2)
		{
			if (*str1 == '\0')
			{
				return 0;
			}
			str1++;
			str2++;
		}
		else if (*str1 > *str2)
		{
			return 1;
		}
		else
		{
			return -1;
		}
	}

}
//int main()
//{
//	char arr1[20] = "abcdef\0XXXXXXX";
//	char arr2[] = "abs";
//	int tmp=my_strncmp(arr1, arr2, 3);
//	printf("%d\n", tmp);
//	return 0;
//}
char* my_strstr(char* str1, char* str2)
{
	assert(str1&&str2);
	char* equals = str1;
	char* s2 = str2;
	char* s1 = str1;
	if (str2 == '\0')
	{
		return str1;
	}
	while (*equals)
	{
		s1 = equals;
		s2 = str2;
		while (*s1!='\0'&&*s2!='\0'&&*s1 == *s2)
		{
			s1++;
			s2++;
		}		
		if (*s2 == '\0')
		{
			return equals;
		}
		equals++;
	}
	return NULL;
}
//int main()
//{
//	char arr[] = "i am a beauty";
//	char arr2[] = " ";
//	char* ret=my_strstr(arr, arr2);
//	printf("%s\n", ret);
//	return 0;
//}
//int main()
//{
//	char arr[] = "i am a beauty";
//	char arr2[] = " ";
//	char arr3[20];
//	strcpy(arr3, arr);
//	for (char* ret = strtok(arr3, arr2); ret != NULL; ret = strtok(NULL, arr2))
//	{
//		printf("%s\n", ret);
//	}
//	return 0;
//}
void* my_memcpy(void* dest, void* src, size_t count)
{
	assert(dest&&src);
	void * ret = dest;
	while (count--)
	{
		*(char*)dest = *(char*)src;
		dest = (char*)dest + 1;
		src = (char*)src + 1;
	}
	return ret;
}
typedef struct Person
{
	char arr[10];
	char arr1[11];
	int class;
}Person;
void* my_memmove1(void* dest, void* src, size_t count)
{
	assert(dest&&src);
	void * ret = dest;
	while (count--)
	{
		*(char*)dest = *(char*)src;
		dest = (char*)dest + 1;
		src = (char*)src + 1;
	}
	return ret;
}
//int main()
//{
//	 Person a1[] = { { "zhangsan", "1999345", 2 }, {"lisi","1224453",4} };
//	 Person a2[2];
//	int arr1[] = { 12, 3, 44, 5, 6, 7 };
//	int arr2[10] = { 0 };
//	my_memcpy(a2, a1, sizeof(a1));
//	for (int i = 0; i < 2; i++)
//	{
//		printf("%s\n", a2[i].arr);
//		printf("%s\n", a2[i].arr1);
//		printf("%d\n", a2[i].class);
//	}
//	return 0;
//}
void* my_memmove( void* dest,const void* src, size_t count)
{
	assert(dest&&src);
	void * tmp = dest;
	if (dest > src)
	{
		for (int i = count-1; i >= 0; i--)
		{
			*((char*)tmp + i) = *((char*)src + i);
		}
	}
	else if (dest<src)
	{
		for (int i =0; i<=count-1; i++)
		{
			*((char*)tmp + i) = *((char*)src + i);
		}
	}
	return dest;
}
//int main()
//{
//	int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//
//	my_memmove(arr, arr +4, 16);
//	for (int i = 0; i < 10; i++)
//	{
//		printf("%d ", arr[i]);
//	}
//	return 0;
//}
//int main()
//{
//	int arr1[] = { 1, 2, 3, 4, 5, 6 };
//	int arr2[] = { 1, 3, 3, 4, 6, 7, };
//	int tmp=memcmp(arr1, arr2, 5);
//	printf("%d\n", tmp);
//	return 0;
//}
//int main()
//{
//	int arr[4] = { 0 };
//	memset(arr, 1, 16);
//	return 0;
//
//}
int main()
{
	printf("%s\n",strerror(-1));
	return 0;
}